/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.web.control;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.losenote.base.util.LogUtil;
import com.losenote.service.CategoryService;
import com.losenote.service.result.CategoryResult;

/**
 * 目录操作服务
 * 
 * @author danjingyu
 * @version $Id: CategoryController.java, v 0.1 2013-9-11 上午12:07:00 danjingyu Exp $
 */
@Controller
public class CategoryController {

    /**logger*/
    private Logger          logger = Logger.getLogger(CategoryController.class);

    /**分类操作服务*/
    @Autowired
    private CategoryService categoryService;

    /**
     * 加载一级目录
     * 
     * @param httpservletrequest
     * @param modelMap
     * @return
     * @throws Exception
     */
    @RequestMapping("/findCategory.htm")
    public ModelAndView loadCategroy(HttpServletRequest httpservletrequest, ModelMap modelMap)
                                                                                              throws Exception {
        ModelAndView view = new ModelAndView("home/findCategory");
        int categoryId = NumberUtils.toInt(httpservletrequest.getParameter("categoryId"));
        CategoryResult result = categoryService.queryChidren(categoryId);
        LogUtil.info(logger, result);
        modelMap.put("result", result);
        return view;
    }

    /**
     * 加载当前目录的子目录
     * 
     * @param httpservletrequest
     * @param modelMap
     * @throws Exception
     */
    @RequestMapping("/findCategory.json")
    @ResponseBody
    public Object loadCategroyChild(HttpServletRequest httpservletrequest) throws Exception {
        int categoryId = NumberUtils.toInt(httpservletrequest.getParameter("categoryId"));
        CategoryResult result = categoryService.queryChidren(categoryId);
        LogUtil.info(logger, result);
        return result;
    }

}
